package com.demo.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.demo.dao.CommentDAO;

public class CommentController extends HttpServlet {
	CommentDAO commentDAO = new CommentDAO();
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html; charset=utf-8");
		// HttpSession session = request.getSession();
		PrintWriter out = response.getWriter();

		String contextPath = request.getContextPath();

		String action = request.getParameter("action");
		if (action == null)
			action = "";
		switch (action) {
		case "list"://列表
			request.setAttribute("comments", commentDAO.list());
			//请求转发和重定向不太一样，请求转发的目标如果以/开头，参照点是当前请求的路径 A请求-》B请求
			request.getRequestDispatcher("/comment_list.jsp").forward(request, response);
			//response.sendRedirect("/comment_list.jsp");
			break;
		default:
			break;
		}
	}

}
